package com.sopaths.utility.scheduler;

import java.util.Map;

import org.quartz.Job;
import org.quartz.JobBuilder;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.springframework.beans.factory.FactoryBean;


public class JobDetailFactoryBean implements FactoryBean<JobDetail> {
	private String group;

	private String name;

	private Class<? extends Job> className;

	private Map<String, Object> jobDataMap;

	@Override
	public JobDetail getObject() throws Exception {
		JobDetail jobDetail = JobBuilder.newJob(className)
				.withIdentity(name, group)
				.build();
		JobDataMap jobDataMap = jobDetail.getJobDataMap();
		if (this.jobDataMap != null) {
			for (String key : this.jobDataMap.keySet()) {
				jobDataMap.put(key, this.jobDataMap.get(key));
			}
		}
		return jobDetail;
	}

	@Override
	public Class<?> getObjectType() {
		return JobDetail.class;
	}

	@Override
	public boolean isSingleton() {
		return false;
	}

	public String getGroup() {
		return group;
	}

	public void setGroup(String group) {
		this.group = group;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Class<? extends Job> getClassName() {
		return className;
	}

	public void setClassName(Class<? extends Job> className) {
		this.className = className;
	}

	public Map<String, Object> getJobDataMap() {
		return jobDataMap;
	}

	public void setJobDataMap(Map<String, Object> jobDataMap) {
		this.jobDataMap = jobDataMap;
	}
}
